package com.czy.util.json;

import com.czy.convert.Converter;
import com.czy.util.StringUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

public class DeserializerStr2Bool extends JsonDeserializer<Boolean> implements Converter<String, Boolean> {
    @Override
    public Boolean deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        return convert(p.getText().strip());
    }

    @Override
    public Boolean convert(String source) {
        return StringUtil.getBoolean(source);
    }
}
